/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bsc.war.form;

import bsc.ejb.metadata.Comparation;
import bsc.ejb.metadata.Framework;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author luisZavaleta
 */
public class AddComparation extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

            HttpSession session = request.getSession();
            ModelAndView mav = new ModelAndView("addComparation");
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");

            Framework framework = delegate.findFramework((Long)session.getAttribute("frameworkId"));

             String type = request.getParameter("type");

            if("edit".equals(type)){
                if(NumberUtils.isDigits(request.getParameter("id"))){
                    mav.addObject("comparate", delegate.findComparation(Long.valueOf(request.getParameter("id"))));
                }
            }
            List<Comparation> comparations = delegate.findComparation(framework, Boolean.TRUE);
            mav.addObject("comparations",comparations);

            return mav;

    }

}
